Skip to main content

Terraform

What is Terraform?

Terraform Logo

Terraform enables you to create, change, and improve infrastructure safely and predictably. It is an open-source tool that codifies APIs into declarative configuration files that can be shared among co-workers, treated as code, edited, reviewed, and versioned. It is an infrastructure as code (IaC) tool that allows you to build, change, and version infrastructure safely and efficiently. This includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.

Configuration files describe to Terraform the components needed to run a single application or your entire data centre. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform can determine what changed and create incremental execution plans that can be applied.

The easy way of explaining terraform is through this example here:

So, say you're driving in your car, trying to get from point A to point B. Generally, you would follow a set of instructions, you have to take a left turn, get on the highway, take this exit- you end up at your destination. Now, that's kind of an imperative approach to automation.

The way Terraform does it: imagine you called a taxi or a rideshare service and told them exactly where you wanted to go - point B. The car, or the driver, then takes care of the rest- you don't have to worry about every step of the way to get there and that's the approach Terraform takes. That's why it's so effective at managing your infrastructure.

Terraform working

Key features:

  • Infrastructure as code Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your data center to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.
  • Execution plans Terraform has a planning step in which it generates an execution plan. The execution plan shows what Terraform will do when you execute the apply command. This lets you avoid any surprises when Terraform manipulates infrastructure.
  • Resource graph Terraform builds a graph of all your resources and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.
  • Change automation Complex changesets can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph, you know exactly what Terraform will change and in what order, which helps you avoid many possible human errors.Terraform features

Use Cases:

The following are some typical use cases for Terraform:

  • You need to automate the orchestration of a large number of resources.

  • You have developer resources to support the development of Terraform code.

  • You need to scale up and down the infrastructure according to variable online workloads.

  • You need to deploy a large system that involves a complex topology.

  • You need to apply repeated, clearly defined procedures on cloud resources.

  • You need to perform orchestration on a large heterogeneous system that involves multi-cloud and hybrid cloud platforms.

Happy Learning!!